//
//  MyAskLeave.m
//  SchoolTask
//
//  Created by feel on 16/8/26.
//  Copyright © 2016年 sm. All rights reserved.
//

#import "MyAskLeave.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height

@interface MyAskLeave ()

@property (nonatomic,retain) UIView  *askLeaveView;      //请假
@property (nonatomic,retain) UIView  *roundView;         //圆
@property (nonatomic,retain) UILabel *studentNameLb;     //学生姓名
@property (nonatomic,retain) UILabel *studentInfoLb;     //学生信息简介
@property (nonatomic,retain) UILabel *statusLb;          //状态

@property (nonatomic,retain) UIView *leaveInfoView;     //请假信息详情
@property (nonatomic,retain) UILabel *numberInfo;       //审批编号
@property (nonatomic,retain) UILabel *className;        //班级名称
@property (nonatomic,retain) UILabel *leaveType;        //请假类型
@property (nonatomic,retain) UILabel *startTime;        //开始时间
@property (nonatomic,retain) UILabel *endTime;          //结束时间
@property (nonatomic,retain) UILabel *numberOfDate;     //请假天数
@property (nonatomic,retain) UILabel *leaveReason;      //请假原因

@property (nonatomic,retain) UIView  *studentApplyView;       //学生申请
@property (nonatomic,retain) UIView  *roundViewApply;         //圆
@property (nonatomic,retain) UILabel *studentNameLbApply;     //学生姓名
@property (nonatomic,retain) UILabel *studentInfoLbApply;     //学生信息简介
@property (nonatomic,retain) UILabel *statusLbApply;          //状态
@property (nonatomic,retain) UILabel *timeLbApply;            //发送消息时间

@property (nonatomic,retain) UIView  *teacherLotusView;  //老师审批
@property (nonatomic,retain) UIView  *roundViewTeacher;  //圆
@property (nonatomic,retain) UILabel *teacherLb;         //展示 老师
@property (nonatomic,retain) UILabel *meLb;              //老师 展示  我
@property (nonatomic,retain) UILabel *statusOfTeacher;   //老师审批状态

@property (nonatomic,retain) UIView  *HandleBtView;      //承载底部按钮的view

@end

@implementation MyAskLeave

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.frame = [UIScreen mainScreen].bounds;
        [self setViewAndLabel];
        self.backgroundColor = [UIColor colorWithRed:230/255.0 green:235/255.0 blue:235/255.0 alpha:1];
    }
    return self;
}

- (void)setViewAndLabel {
    
    [self setAskLeaveView];
    [self setLeaveInfoView];
    [self setStudentApplyView];
    [self setTeacherLotusView];
    [self setHandleBtView];
}

- (void)setAskLeaveView {
    
    CGFloat h = 736 / kScreenH;
    CGFloat w = 414 / kScreenW;
    _askLeaveView = [[UIView alloc]initWithFrame:CGRectMake(0, 80/h, kScreenW, 80/h)];
    _askLeaveView.backgroundColor = [UIColor whiteColor];
    
    //画圆
    _roundView = [[UIView alloc]initWithFrame:CGRectMake(20/w, 5/h, 70/h, 70/w)];
    _roundView.layer.cornerRadius = 35;
    _roundView.layer.backgroundColor = [[UIColor colorWithRed:100/255.0 green:190/255.0 blue:250/255.0 alpha:1] CGColor];
    _roundView.layer.shouldRasterize = YES;
    
    //圆上加字
    _studentNameLb = [[UILabel alloc]initWithFrame:CGRectMake(10/h, 15/w, 80/h, 30/w)];
    _studentNameLb.text = @"郑建华";
    _studentNameLb.textColor = [UIColor whiteColor];
    _studentNameLb.font = [UIFont systemFontOfSize:15/h];
    
    //学生相关信息
    _studentInfoLb = [[UILabel alloc]initWithFrame:CGRectMake(120/w, 20/h, 300/w, 30/h)];
    _studentInfoLb.text = @"小明 艺术设计系 广告班请假";
    _studentInfoLb.font = [UIFont boldSystemFontOfSize:20/h];
    _studentInfoLb.textColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
    
    //statusLb审批状态
    _statusLb = [[UILabel alloc]initWithFrame:CGRectMake(120/w, 50/h, 200/w, 30/h)];
    _statusLb.text = @"等待审批";
    _statusLb.font = [UIFont boldSystemFontOfSize:20/h];

    _statusLb.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];
    
    [_askLeaveView addSubview:_statusLb];
    [_askLeaveView addSubview:_studentInfoLb];
    [_roundView addSubview:_studentNameLb];
    [_askLeaveView addSubview:_roundView];
    [self addSubview:_askLeaveView];

}

- (void)setLeaveInfoView {
    
    CGFloat h = 736 / kScreenH;
    CGFloat w = 414 / kScreenW;
    _leaveInfoView = [[UIView alloc]initWithFrame:CGRectMake(0, 170/h, kScreenW, 200/h)];
    _leaveInfoView.backgroundColor = [UIColor whiteColor];
    
    NSArray *array = [NSArray arrayWithObjects:@"审批编号:",@"所在班级:",@"请假类型:",@"开始时间:",@"结束时间:",@"请假天数:",@"请假理由:", nil];
    
    CGFloat hL = (_leaveInfoView.frame.size.height) / array.count;
    for (NSInteger i = 0; i < array.count; i++) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(40/w, ( (hL+1)*i)/h, 100/w, 25/h)];
        NSLog(@"label -- %f",label.frame.origin.y);
        label.text = array[i];
        label.font = [UIFont boldSystemFontOfSize:19/w];
        label.textColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
        [_leaveInfoView addSubview:label];
        label.textAlignment = 2;
    }

    _numberInfo   = [[UILabel alloc]initWithFrame:CGRectMake(150/w, 0, 200/w, hL/h)];
    _className    = [[UILabel alloc]initWithFrame:CGRectMake(150/w, ((hL+1)*1)/h, 200/w, 25/h)];
    _leaveType    = [[UILabel alloc]initWithFrame:CGRectMake(150/w, ((hL+1)*2)/h, 200/w, 25/h)];
    _startTime    = [[UILabel alloc]initWithFrame:CGRectMake(150/w, ((hL+1)*3)/h, 200/w, 25/h)];
    _endTime      = [[UILabel alloc]initWithFrame:CGRectMake(150/w, ((hL+1)*4)/h, 200/w, 25/h)];
    _numberOfDate = [[UILabel alloc]initWithFrame:CGRectMake(150/w, ((hL+1)*5)/h, 200/w, 25/h)];
    _leaveReason  = [[UILabel alloc]initWithFrame:CGRectMake(150/w, ((hL+1)*6)/h, 200/w, 25/h)];
    
    _numberInfo.text      = @"4182743981247984";
    _numberInfo.font      = [UIFont boldSystemFontOfSize:17/w];
    _numberInfo.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];
    
    _className.text      = @"广告班";
    _className.font      = [UIFont boldSystemFontOfSize:17/w];
    _className.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];

    _leaveType.text      = @"事假";
    _leaveType.font      = [UIFont boldSystemFontOfSize:17/w];
    _leaveType.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];

    _startTime.text      = @"2016.12.12";
    _startTime.font      = [UIFont boldSystemFontOfSize:17/w];
    _startTime.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];

    _endTime.text      = @"2016.12.22";
    _endTime.font      = [UIFont boldSystemFontOfSize:17/w];
    _endTime.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];

    _numberOfDate.text      = @"10";
    _numberOfDate.font      = [UIFont boldSystemFontOfSize:17/w];
    _numberOfDate.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];

    _leaveReason.text      = @"家事";
    _leaveReason.font      = [UIFont boldSystemFontOfSize:17/w];
    _leaveReason.textColor = [UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1];

    [_leaveInfoView addSubview:_numberInfo];
    [_leaveInfoView addSubview:_className];
    [_leaveInfoView addSubview:_leaveType];
    [_leaveInfoView addSubview:_startTime];
    [_leaveInfoView addSubview:_numberOfDate];
    [_leaveInfoView addSubview:_leaveReason];
    [_leaveInfoView addSubview:_endTime];

    [self addSubview:_leaveInfoView];
    
}

- (void)setStudentApplyView {
    
    CGFloat h = 736 / kScreenH;
    CGFloat w = 414 / kScreenW;
    _studentApplyView = [[UIView alloc]initWithFrame:CGRectMake(100/w, 390/h, kScreenW - 130/w, 100/h)];
    _studentApplyView.backgroundColor = [UIColor whiteColor];
    
    //画圆
    _roundViewApply = [[UIView alloc]initWithFrame:CGRectMake(20/w, 15/h, 70/w, 70/h)];
    _roundViewApply.layer.cornerRadius = 35;
    _roundViewApply.layer.backgroundColor = [[UIColor colorWithRed:100/255.0 green:190/255.0 blue:250/255.0 alpha:1] CGColor];
    _roundViewApply.layer.shouldRasterize = YES;
    
    //圆上加字
    _studentNameLbApply      = [[UILabel alloc]initWithFrame:CGRectMake(10/w, 15/h, 80/w, 30/h)];
    _studentNameLbApply.text = @"郑建华";
    _studentNameLbApply.textColor = [UIColor whiteColor];
    _studentNameLbApply.font = [UIFont systemFontOfSize:15/w];
    
    //学生相关信息
    _studentInfoLbApply      = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 20/h, 300/w, 30/h)];
    _studentInfoLbApply.text = @"小明 艺术设计系 广告班";
    _studentInfoLbApply.font = [UIFont boldSystemFontOfSize:15/w];
    _studentInfoLbApply.textColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
    
    //statusLb审批状态
    _statusLbApply      = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 50/h, 200/w, 30/h)];
    _statusLbApply.text = @"发起申请";
    _statusLbApply.font = [UIFont boldSystemFontOfSize:20/w];
    _statusLbApply.textColor = [UIColor colorWithRed:150/255.0 green:210/255.0 blue:90/255.0 alpha:1];

    //_timeLbApply时间显示
    _timeLbApply      = [[UILabel alloc]initWithFrame:CGRectMake(_studentApplyView.frame.size.width-140/w, 5/h, 130/w, 20/h)];
    _timeLbApply.text = @"2016.12.12 22:30";
    _timeLbApply.font = [UIFont systemFontOfSize:15/w];
    _timeLbApply.textColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
    
    [_studentApplyView addSubview:_roundViewApply];
    [_roundViewApply addSubview:_studentNameLbApply];
    [_studentApplyView addSubview:_studentInfoLbApply];
    [_studentApplyView addSubview:_statusLbApply];
    [_studentApplyView addSubview:_timeLbApply];
    [_studentApplyView addSubview:_timeLbApply];
    [self addSubview:_studentApplyView];
}

- (void)setTeacherLotusView {
    
    CGFloat h = 736 / kScreenH;
    CGFloat w = 414 / kScreenW;
    _teacherLotusView = [[UIView alloc]initWithFrame:CGRectMake(30/w, 510/h, kScreenW - 130/w, 100/h)];
    _teacherLotusView.backgroundColor = [UIColor whiteColor];
    
    //画圆
    _roundViewTeacher = [[UIView alloc]initWithFrame:CGRectMake(20/w, 15/h, 70/w, 70/h)];
    _roundViewTeacher.layer.shouldRasterize = YES;
    _roundViewTeacher.layer.cornerRadius = 35;
    _roundViewTeacher.layer.backgroundColor = [[UIColor colorWithRed:250/255.0 green:100/255.0 blue:140/255.0 alpha:1] CGColor];
    
    //圆上加字
    _teacherLb      = [[UILabel alloc]initWithFrame:CGRectMake(10/w, 15/h, 80/w, 30/h)];
    _teacherLb.text = @"老师";
    _teacherLb.textColor = [UIColor whiteColor];
    _teacherLb.font = [UIFont systemFontOfSize:15/w];
    
    //学生相关信息
    _meLb      = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 10/h, 300/w, 30/h)];
    _meLb.text = @"我";
    _meLb.font = [UIFont boldSystemFontOfSize:15/w];
    _meLb.textColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
    
    //学生相关信息
    _statusOfTeacher      = [[UILabel alloc]initWithFrame:CGRectMake(100/w, 60/h, 300/w, 30/h)];
    _statusOfTeacher.text = @"审批中";
    _statusOfTeacher.font = [UIFont boldSystemFontOfSize:15/w];
    _statusOfTeacher.textColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];

    [_roundViewTeacher addSubview:_teacherLb];
    [_teacherLotusView addSubview:_roundViewTeacher];
    [_teacherLotusView addSubview:_meLb];
    [_teacherLotusView addSubview:_statusOfTeacher];
    [self addSubview:_teacherLotusView];
}

- (void)setHandleBtView {
    
    CGFloat h = 736 / kScreenH;
    CGFloat w = 414 / kScreenW;
    _HandleBtView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH - 70/h, kScreenW, 70/h)];
    _HandleBtView.backgroundColor = [UIColor whiteColor];
    
    NSArray *array = [NSArray arrayWithObjects:@"同意",@"拒绝",@"转交",@"评论", nil];
    NSInteger vule = 1000;
    CGFloat wH = _HandleBtView.frame.size.width/4;
    for (NSInteger i = 0; i<array.count; i++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame     = CGRectMake(wH*i, 15/h, wH/w, 55/h);
        [button setTitle:array[i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.titleLabel.textColor = [UIColor whiteColor];
        [button setTitleColor:[UIColor colorWithRed:90/255.0 green:180/255.0 blue:250/255.0 alpha:1] forState:UIControlStateSelected];
        [button setTitleColor:[UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1] forState:UIControlStateNormal];
        button.tag = vule;
        if (i == 0) {
            
            button.selected = YES;
        }
        vule ++;
        button.font = [UIFont boldSystemFontOfSize:20/w];
        [_HandleBtView addSubview:button];
    }
   

    [self addSubview:_HandleBtView];
}

- (void)buttonAction:(UIButton *)button {
    
    button.selected =! button.selected;

    NSLog(@"MyAskLeave中底部bt,在合代码时在viewcontroller中设置button的选中状态");
}

@end
